<?php
require_once('../db.php');
pr($_POST);
pr($_FILES);
$msg = '';
  $validExtn = array('png',
                     'jpeg',
                     'jpg',
                     'gif' );

if(isset($_FILES['avatar']['error']) && $_FILES['avatar']['error']==0) {
  $fileName = $_FILES['avatar']['name'];
  pr($fileName);
  $fileDetails = pathinfo($fileName);
  $fileExtn = $fileDetails['extension'];
  pr($fileExtn);
  if(!in_array($fileExtn,$validExtn)) {

    $msg = "Please uplaod file with valid extn(".implode(',',$validExtn).")";
  }
} else if(isset($_FILES['avatar']['error'])){
  $msg = "There might be some error during upload, please try again.";
}

if($msg != '') {
  echo "<div class=\"error\">$msg</div>";
}
?>
<form action=""
enctype="multipart/form-data"
method="post">
  <input type="file" name="avatar" />
  <input type="submit" value="Upload" name="sbmt"/>
</form>
<style type="text/css">
  .error{
    border:1px solid red;
    padding:10px;
    margin:10px;
    background-color:pink;
    border-radius:5px;
  }
</style>
